package cn.fengzhilun.javase.day10.ex;

import static org.junit.Assert.assertArrayEquals;

import java.util.Arrays;
import java.util.Comparator;

import org.junit.Test;

public class TestSort {
	@Test
	public void test() {
		int[] array= {1,2,5,4,3,9,6,8};
		
		Arrays.sort(array);
		
		System.out.println(array);
		System.out.println(Arrays.toString(array));
		
		System.out.println(array.toString());
	
	}
	
	@Test
	public void test1() {
		String[] array= {"ab","abc","bc","de","bb"};
		
		Arrays.sort(array);
		
		System.out.println(Arrays.toString(array));
	}
	@Test
	public void Test2() {
		String[] array= {"ab","abc","bc","de","bb"};
		
		String[] except= {"ab","bc","de","bb","abc"};
		Arrays.sort(array, new StringComparator());
		
		System.out.println(Arrays.toString(array));
		
		assertArrayEquals(except, array);
	}
	
	@Test
	public void Test3() {
		String[] array= {"ab","abc","bc","de","bb"};
		
		String[] except= {"ab","bc","de","bb","abc"};
		
//		Arrays.sort(array, new Comparator<String>() {
//
//			@Override
//			public int compare(String o1, String o2) {
//				
//				return o1.length()-o2.length();
//			}
//		});
		Arrays.sort(array, (o1, o2)->{
			
			return o1.length()-o2.length();
		});
		assertArrayEquals(except, array);
		System.out.println(Arrays.toString(array));
		}
	@Test
	public void test5() throws InterruptedException {
		//第一种用内部类
		//Thread t=new Thread(new Task());
		//第二种是匿名内部类（只有一个方法的时候才能使用）
//		Thread t=new Thread(new Runnable() {
//
//			@Override
//			public void run() {
//				System.out.println("匿名内部类。。哈哈");
//			}});
		//第三种是拉姆达符号（要求是接口而且接口里面只有一个方法）
		Thread t=new Thread(()-> {
			System.out.println("lamda....");
		});
		t.start();
		Thread.sleep(1000);
	}
	class Task implements Runnable{

		@Override
		public void run() {
			System.out.println("Runnable跑起来了");
		}
		
		
	}
}
class StringComparator implements Comparator<String>{

	@Override
	public int compare(String o1, String o2) {
		//return o1.compareTo(o2);
		int len1=o1.length();
		int len2=o2.length();
		
		if(len1>len2) {
			return 1;
		}else if(len1==len2) {
			return 0;
		}else {
			return -1;
		}
	}
}
